package com.boot.web.serviceImpl;

import com.boot.web.dao.SpecAttributeDao;
import com.boot.web.entity.SpecAttribute;
import com.boot.web.vo.SkuRelationVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.boot.web.dao.SkuRelationDao;
import com.boot.web.entity.SkuRelation;
import com.boot.web.service.SkuRelationService;
import com.boot.base.serviceImpl.BaseServiceImpl;

import java.util.List;
import java.util.Map;

/**
 * 产品SKU关系业务层接口实现
 * @author 【zhouJie】
 * @date 2021-06-02 08:43:22
 */
@Service
public class SkuRelationServiceImpl extends BaseServiceImpl<SkuRelation> implements SkuRelationService {

    private static final Logger logger = LoggerFactory.getLogger(SkuRelationServiceImpl.class);

    @Autowired
    private SkuRelationDao skuRelationDao;

    @Autowired
    private SpecAttributeDao specAttributeDao;

    @Override
    public List<SkuRelationVO> getSkuRelationVOPageList(Map<String, Object> map) {
        List<SkuRelationVO> voList = skuRelationDao.getSkuRelationVOPageList(map);
        if(voList.size() > 0){
            for(SkuRelationVO vo : voList){
                String sku = vo.getGroupRelation();
                if(sku.contains(",")){
                    String[] skus = sku.split(",");
                    String str = "";
                    for(int i = 0; i < skus.length; i++){
                        SpecAttribute sa = specAttributeDao.queryById(Integer.parseInt(skus[i]));
                        str += sa.getAttributeName() + "，";
                    }
                    vo.setSpecAttributeNames(str.substring(0, str.length() - 1));
                }else{
                    vo.setSpecAttributeNames(specAttributeDao.queryById(Integer.parseInt(sku)).getAttributeName());
                }
            }
        }
        return voList;
    }
}
